$(function(){
    berserker.addView({
        name:'qwbd',
        tpl:'tpl_qwbd',
        dataURL:'/api/qwbd.json',
        coverRight:true,
        done:function(host,data){
            bindNav();

            $('embed',host).attr('src',$('.top-nav-act',host).attr('data-url'))


            function bindNav(){
                var pIndex = 0,
                pageSize = 6,
                pItemCount = $('.top-nav-box li',host).size(),
                pWidth = $('.top-nav-box li:first',host).width(),
                pageCount = Math.ceil( pItemCount / pageSize ) ,
                domCenter = $('#frm_center');

                $('.top-nav-box',host).css('width',pWidth * pItemCount);
                $('.top-nav-box li',host).click(function(evt){
                    var that = this;
                    if($(that).hasClass('top-nav-act')){return;}
                    $('.top-nav-act',this.parentNode).removeClass('top-nav-act');
                    this.className = 'top-nav-act';
                    $('embed',host).attr('src',that.getAttribute('data-url'))
                })

                /******************上一页,下一页*******************/
                $('.nav-pre',host).click(function(evt){
                    if(pIndex == 0)return;
                    //上一页
                    pIndex--;
                    $('.top-nav-box').css('margin-left',-pIndex * pageSize * pWidth+'px');
                })
                $('.nav-next',host).click(function(evt){
                    //下一页
                    if(pIndex>=pageCount-1)return;
                    pIndex++;
                    $('.top-nav-box',host).css('margin-left',-pIndex * pageSize * pWidth+'px');
                })
                /******************上一页,下一页 END *******************/
            }

        }
    })
})


